import request from '@/config/axios'
import { yuanToFenWithNullCheck } from '@/utils'

// 套餐 VO
export interface PackageVO {
  id: number // ID
  name: string // 套餐名称
  categoryId: number // 种类ID
  categoryName: string // 种类名称
  description: string // 套餐描述
  picUrl: string // 宣传图片
  price: number // 首开价格
  renewPrice: number // 续费价格
  status: number // 状态
  remark: string // 备注

}

// 套餐 API
export const PackageApi = {
  // 查询套餐分页
  getPage: async (params: any) => {
    return await request.get({ url: `/package/packages/page`, params })
  },

  // 查询套餐详情
  get: async (id: number) => {
    return await request.get({ url: `/package/packages/get?id=` + id })
  },

  // 新增套餐
  create: async (data: PackageVO) => {
    data.price = yuanToFenWithNullCheck(data.price)
    data.renewPrice = yuanToFenWithNullCheck(data.renewPrice)
    return await request.post({ url: `/package/packages/create`, data })
  },

  // 修改套餐
  update: async (data: PackageVO) => {
    data.price = yuanToFenWithNullCheck(data.price)
    data.renewPrice = yuanToFenWithNullCheck(data.renewPrice)
    return await request.post({ url: `/package/packages/update`, data })
  },

  // 删除套餐
  delete: async (id: number) => {
    return await request.get({ url: `/package/packages/delete?id=` + id })
  },

  // 导出套餐 Excel
  export: async (params) => {
    return await request.download({ url: `/package/packages/export-excel`, params })
  },

  simpleList: async () => {
    return await request.get({url: `/package/packages/list/simple?name=`+'null'})
  }
}